package com.wuyoucar.controller;

import com.alibaba.fastjson.JSON;
import com.sun.tracing.dtrace.ArgsAttributes;
import com.wuyoucar.service.ICalculatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: jiangdz
 * @ProjectName: mywuyou_car
 * @Package: com.wuyoucar.controller
 * @ClassName: CalculatorController
 * @Description:
 * @Date: 2020-09-22  15:30
 * @UpdateUser: asus
 * @UpdateDate: 2020-09-22  15:30
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 * @Since JDK 1.8
 */
@RequestMapping("/calculator")
@RestController
public class CalculatorController {

    @Autowired
    private ICalculatorService iCalculatorService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @RequestMapping("/calculator")
    public Double calculator(@RequestParam(required = false,defaultValue = "1，2，3，4")int[] id,
                             @RequestParam(required = false,defaultValue = "50") int compensateLines,
                             @RequestParam(required = false,defaultValue = "200000") int price,
                             @RequestParam(required = false,defaultValue = "2") int scratchLines,
                             @RequestParam(required = false,defaultValue = "1") int seating,
                             @RequestParam(required = false,defaultValue = "1") int year,
                             @RequestParam(required = true)int userid ){
        //车责一人
        int personnel = 1;
        Double cost = iCalculatorService.calculator(id,compensateLines, price, personnel, scratchLines,seating, year);
        String safetypeitemid = "safetypeitemid"+userid;
        stringRedisTemplate.opsForValue().set(safetypeitemid,JSON.toJSONString(id));
        return cost;
    }
    //    首页计算器
    @RequestMapping("/simpleCalculator")
    public Double simpleCalculator(@RequestParam(required = false,defaultValue = "200000") int price){
        //首页计算器默认1 是机动车损失保险 ；2 第三者责任保险  ； 3 车上人员责任险；4 车身划痕险 全选
        int[] id = {1, 2, 3, 4};
//        三者赔付额度
        int compensateLines = 50;
        //车责一人
        int personnel = 1;
        //划痕2千
        int scratchLines = 2;
        //默认私家车6座以下
        int seating = 1;
        //车龄为一年
        int year = 1;
        Double cost = iCalculatorService.calculator(id,compensateLines, price, personnel, scratchLines,seating, year);
        return cost;
    }

}
